from django.contrib import admin
from django.contrib.admin.models import LogEntry
from modelclone import ClonableModelAdmin

from .models import Business, Environment, Application, Instances, Language, Resource
from .site import cmdb_site


class BaseOwnerAdmin(ClonableModelAdmin):
    pass


@admin.register(Business, site=cmdb_site)
class BusinessAdmin(BaseOwnerAdmin):
    pass


@admin.register(Instances, site=cmdb_site)
class InstancesAdmin(BaseOwnerAdmin):
    pass


@admin.register(Language, site=cmdb_site)
class LanguageAdmin(BaseOwnerAdmin):
    list_filter = ('name',)
    search_fields = ('name',)


@admin.register(Resource, site=cmdb_site)
class ResourceAdmin(BaseOwnerAdmin):
    list_filter = ('name',)
    search_fields = ('name',)


@admin.register(LogEntry, site=cmdb_site)
class LogEntryAdmin(BaseOwnerAdmin):
    list_display = ['object_repr', 'object_id', 'action_flag', 'user', 'change_message']


@admin.register(Application, site=cmdb_site)
class ApplicationAdmin(BaseOwnerAdmin):
    # list_display = (
    # 'id', 'created_by', 'created_at', 'updated_by', 'updated_at', 'name', 'desc', 'type', 'path', 'port', 'image',
    # 'domain', 'business')
    list_filter = ('business', 'language', 'resource')
    search_fields = ('name',)


@admin.register(Environment, site=cmdb_site)
class EnvironmentAdmin(BaseOwnerAdmin):
    # list_display = ('business','name','private_ip','public_ip')
    list_filter = ('business', 'name',)
    search_fields = ('name',)
